package com.gnerv.sylvanas.framework.core.interceptor;

import com.gnerv.sylvanas.framework.core.tools.TimeTrackerTools;
import jakarta.annotation.Nonnull;
import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
 * @author Gnerv LiGen
 */
@Slf4j
public class MethodExecutionTimeInterceptor implements MethodInterceptor {

    @Override
    public Object invoke(@Nonnull MethodInvocation invocation) throws Throwable {
        Method method = invocation.getMethod();
        String clazzName = method.getDeclaringClass().getName();
        String methodName = method.getName();
        return TimeTrackerTools.track(clazzName + "." + methodName, invocation::proceed);
    }

}
